/**
 * 路由文件
 */

import Vue from "vue";
import Router from "vue-router";
import mRouter from "./mRouter";
import Layout from "@/layout";
import Layout2 from "@/layout2";
import Layout3 from "@/layout3";
import tabbar from "./tabbar";
import tabbar2 from "./tabbar2";
import tabbar3 from "./tabbar3";
mRouter.initRouter(Router, tabbar, tabbar2, tabbar3);
Vue.use(Router);

//静态路由列表
export const constantRoutes = [
  {
    path: "/",
    component: Layout,
    redirect: "/home",
    children: [
      {
        path: "/login",
        name: "login",
        component: () => import("@/view/login/index"),
        meta: { tabbar: false, navbar: false },
      },
      {
        path: "/register",
        name: "register",
        component: () => import("@/view/user/register"),
        meta: { tabbar: false, navbar: false },
      },
      {
        path: "/forgot-password",
        name: "forgot-password",
        component: () => import("@/view/user/forgot-password"),
        meta: { tabbar: false, navbar: false },
      },
      {
        path: "/phone",
        name: "phone",
        component: () => import("@/view/user/phone"),
        meta: { tabbar: false, navbar: false },
      },
      {
        path: "/change-password",
        name: "change-password",
        component: () => import("@/view/user/change-password"),
        meta: { tabbar: false, navbar: false },
      },
      {
        path: "/addarea",
        name: "addarea",
        component: () => import("../view/fishing-pond/add-pond.vue"),
        meta: { tabbar: false, navbar: false },
      },
      {
        path: "/editarea",
        name: "editarea",
        component: () => import("../view/fishing-pond/edit-pond.vue"),
        meta: { tabbar: false, navbar: false },
      }

    ],
  },
  {
    path: "/",
    component: Layout,
    children: tabbar,
  },
  // 渔塘
  {
    path: "/fish",
    name: "fish",
    component: Layout2,
    children: tabbar2,
  },
  {
    path: "/fish",
    name: "fish",
    component: Layout2,
    children: [
      // 添加池塘
      {
        path: "/add-pond",
        name: "add-pond",
        component: () => import("../view/fishing-pond/add-pond.vue"),
        meta: { tabbar: true, navbar: false },
      },
      // 设备列表
      {
        path: "/equipment-list",
        name: "equipment-list",
        component: () => import("../view/equipment/index.vue"),
        meta: { tabbar: true, navbar: false },
      },
      {
        path: "/tq-list",
        name: "tq-list",
        component: () => import("../view/tq/index.vue"),
        meta: { tabbar: false, navbar: false },
      },
      // 摄像机
      {
        path: "/camera",
        name: "camera",
        component: () => import("@/view/equipment/camera"),
        meta: { tabbar: true, navbar: false },
      },
      // 定时任务
      {
        path: "/timing-switch",
        name: "timing-switch",
        component: () => import("../view/equipment/timing-switch.vue"),
        meta: { tabbar: false, navbar: false },
      },
      // 添加任务
      {
        path: "/add-task",
        name: "add-task",
        component: () => import("../view/equipment/add-task.vue"),
        meta: { tabbar: false, navbar: false },
      },
      // 阀值设置
      {
        path: "/fazhi",
        name: "fazhi",
        component: () => import("../view/equipment/fazhi.vue"),
        meta: { tabbar: false, navbar: false },
      },
      // 阀值设置
      {
        path: "/errorlog",
        name: "errorlog",
        component: () => import("../view/user/errorlog.vue"),
        meta: { tabbar: false, navbar: false },
      },
      {
        path: "/fazhilist",
        name: "fazhilist",
        component: () => import("../view/equipment/fazhilist.vue"),
        meta: { tabbar: false, navbar: false },
      },
      {
        path: "/switch-info",
        name: "switch-info",
        component: () => import("../view/equipment/switch-info.vue"),
        meta: { tabbar: false, navbar: false },
      },
      // 开关改名
      {
        path: "/switch-rename",
        name: "switch-rename",
        component: () => import("../view/equipment/switch-rename.vue"),
        meta: { tabbar: false, navbar: false },
      },
      // 水质仪详情
      {
        path: "/water-details",
        name: "water-details",
        component: () => import("../view/equipment/water-details.vue"),
        meta: { tabbar: true, navbar: false },
      },
      // 水质仪图表
      {
        path: "/water-charts",
        name: "water-charts",
        component: () => import("../view/equipment/water-charts.vue"),
        meta: { tabbar: false, navbar: false },
      },
      // 添加渔塘记录
      {
        path: "/add-record",
        name: "add-record",
        component: () => import("../view/fishing-pond/add-record.vue"),
        meta: { tabbar: true, navbar: false },
      },
      // 编辑渔塘记录
      {
        path: "/edit-record",
        name: "edit-record",
        component: () => import("../view/fishing-pond/edit-record.vue"),
        meta: { tabbar: true, navbar: false },
      },
      // 入库
      {
        path: "/init-house",
        name: "init-house",
        component: () => import("../view/warehousing/init-house.vue"),
        meta: { tabbar: true, navbar: false },
      },
      // 添加物料
      {
        path: "/add-material",
        name: "add-material",
        component: () => import("../view/warehousing/add-material.vue"),
        meta: { tabbar: true, navbar: false },
      },
    ],
  },
  //商城
  {
    path: "/shop",
    name: "tabbar3",
    component: Layout3,
    children: tabbar3,
  },
  {
    path: "/shop",
    name: "tabbar3",
    component: Layout3,
    children: [
      // 分类详情
      {
        path: "/class-detail",
        name: "class-detail",
        component: () => import("../view/mall/class-detail.vue"),
        meta: { tabbar: true, navbar: false, active: 2 },
      },
      // 收货地址
      {
        path: "/address",
        name: "address",
        component: () => import("../view/mall/address.vue"),
        meta: { tabbar: true, navbar: false },
      },
      // 新增收货地址
      {
        path: "/add-address",
        name: "add-address",
        component: () => import("../view/mall/add-address.vue"),
        meta: { tabbar: false, navbar: false },
      },
      // 修改收货地址
      {
        path: "/edit-address",
        name: "edit-address",
        component: () => import("../view/mall/edit-address.vue"),
        meta: { tabbar: false, navbar: false },
      },
      // 我的订单
      {
        path: "/my-order",
        name: "my-order",
        component: () => import("../view/mall/my-order.vue"),
        meta: { tabbar: true, navbar: false },
      },
      // 发布商品
      {
        path: "/add-goods",
        name: "add-goods",
        component: () => import("../view/mall/add-goods.vue"),
        meta: { tabbar: false, navbar: false },
      },
      // 商家入驻
      {
        path: "/add-business",
        name: "add-business",
        component: () => import("../view/mall/add-business.vue"),
        meta: { tabbar: false, navbar: false },
      },



      // 提交订单
      {
        path: "/buy",
        name: "buy",
        component: () => import("../view/mall/buy.vue"),
        meta: { tabbar: false, navbar: false },
      },

      // 提交订单
      {
        path: "/submit-order",
        name: "submit-order",
        component: () => import("../view/mall/submit-order.vue"),
        meta: { tabbar: false, navbar: false },
      },
      // 店铺详情
      {
        path: "/shop-detail",
        name: "shop-detail",
        component: () => import("../view/mall/shop-detail.vue"),
        meta: { tabbar: false, navbar: false },
      },
      // 商品详情
      {
        path: "/goods-details",
        name: "goods-details",
        component: () => import("../view/mall/goods-details.vue"),
        meta: { tabbar: false, navbar: false },
      },
      // 商品列表
      {
        path: "/goods",
        name: "goods",
        component: () => import("../view/mall/goods.vue"),
        meta: { tabbar: false, navbar: false },
      },
    ],
  },
  {
    path: "/404",
    component: Layout,
    children: [
      {
        path: "",
        component: () => import("@/view/404/index"),
        hidden: true,
      },
    ],
  },
  {
    path: "*",
    redirect: "/404",
  },
];

//创建一个路由的工厂函数，用于创建路由和用户退出时重置路由
const createRouter = () =>
  new Router({
    mode: "hash",
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

export default router;
